
package com.gp.activity.main;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;

import com.gp.R;
import com.gp.activity.base.BaseActivity;
import com.gp.controls.MyImageView;

public class MainActivity extends BaseActivity {
    // 主界面的Imageview变量
    MyImageView mCityGuid;
    MyImageView mMyWay;
    MyImageView mPictureAlbum;
    MyImageView mSelfGuided;
    MyImageView mTravelGuide;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);
        initView();
        initListeners();

    }

    /**
     * @Title: initView
     * @param
     * @return void
     * @throws
     * @date Jun 13, 2013 1:47:14 PM
     * @version 1.0
     * @Description: 初始化控件
     */
    @SuppressWarnings("deprecation")
    private void initView() {

        mCityGuid = (MyImageView) findViewById(R.id.city_guide);
        mMyWay = (MyImageView) findViewById(R.id.my_way);
        mPictureAlbum = (MyImageView) findViewById(R.id.picture_album);
        mSelfGuided = (MyImageView) findViewById(R.id.self_guided);
        mTravelGuide = (MyImageView) findViewById(R.id.travel_guide);
        // 设置透明度
        mCityGuid.setAlpha(180);
        mMyWay.setAlpha(180);
        mPictureAlbum.setAlpha(180);
        mSelfGuided.setAlpha(180);
        mTravelGuide.setAlpha(180);

    }

    /**
     * @Title: initListeners
     * @param
     * @return void
     * @throws
     * @date Jun 13, 2013 1:47:35 PM
     * @version 1.0
     * @Description: 初始化监听器
     */
    private void initListeners() {

        OnMyImageViewClickListener listener = new OnMyImageViewClickListener();

        mCityGuid.setOnClickListener(listener);
        mMyWay.setOnClickListener(listener);
        mPictureAlbum.setOnClickListener(listener);
        mSelfGuided.setOnClickListener(listener);
        mTravelGuide.setOnClickListener(listener);
    }

    /**
     * @author shijunxing
     * @className OnMyImageViewClickListener
     * @date Jun 13, 2013 1:47:54 PM
     * @version 1.0
     * @Description MyImage的点击监听类
     */
    private class OnMyImageViewClickListener implements OnClickListener {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.city_guide:
                    openActivity(CityGuideActivity.class);
                    break;
                case R.id.my_way:
                    openActivity(MyWayActivity.class);
                    break;
                case R.id.picture_album:
                    openActivity(PictureAlbumActivity.class);
                    break;
                case R.id.self_guided:
                    openActivity(SelfGuideActivity.class);
                    break;
                case R.id.travel_guide:
                    openActivity(TravalGuideActivity.class);
                    break;
                default:
                    break;

            }
        }

    }

    /**
     * @Title: exit  
     * @param @param cont   
     * @return void   
     * @throws 
     * @date Sep 5, 2013 1:03:59 PM
     * @version 1.0
     * @Description: 程序退出方法 
     */
    public static void exit(final Context pContext) {
        
        AlertDialog.Builder builder = new AlertDialog.Builder(pContext);
        builder.setIcon(android.R.drawable.ic_dialog_info);
        builder.setTitle("确定要退出程序吗？");
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                // 退出
              System.exit(0);
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.show();
    }
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            MainActivity.exit(this);
        }
        return super.onKeyDown(keyCode, event);
    }
    
}
